//
//  NetSyncRecord.h
//  KidReading
//
//  Created by YangShuai on 16/6/20.
//  Copyright © 2016年 刘赞黄Telen. All rights reserved.
//

#import <UIKit/UIKit.h>

typedef enum : NSUInteger {
    FileType_None,
    FileType_File,
    FileType_Directory,
}FileType;

typedef void (^DownloadComplete_One)(NSURLResponse *response, NSURL *filePath,NSInteger currentPage, NSArray* alreadyDoneArray, NSError *error);
typedef void (^DownloadComplete_All)(NSArray* pageArray);

@interface NetSyncRecord : NSObject

+ (NetSyncRecord*)shareSingle;
//
//返回创建路径
-(NSString*)getRecordStorePathWithUid:(NSInteger)uid BookId:(NSInteger)bookId CurrentPage:(NSInteger)currentPage RecordTime:(long long)recordTime;

//获取已经存在的文件路径
-(NSString*)getExitRecordFilePathWithUid:(NSInteger)uid BookId:(NSInteger)bookId CurrentPage:(NSInteger)currentPage;

//本地文件管理
//上传(本地远程同步) 注:recordTime与创建路径的recordTime相同
-(void)uploadRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId CurrentPage:(NSInteger)currentPage RecordTime:(long long)recordTime Success:(void(^)(NSURLResponse *response, id responseData))success Failure:(void (^)(NSError* error))failure;

//获取(获取本地对应页录音)
-(NSData*)getRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId CurrentPage:(NSInteger)currentPage;

//按keyPath取消上传任务
-(void)cancelUploadTaskWithKeyPath:(NSString*)keyPath;
//全部取消
-(void)cancelAllUploadTask;

//下载
//同步服务器录音列表
-(void)synaNetRecordsListWithUid:(NSInteger)uid BookId:(NSInteger)bookId Success:(void(^)(NSArray* listArray))success Failure:(void (^)(NSError *error))failure;
//确定服务器数据是否与本地数据一致
-(BOOL)localRecordListCompareNetRecordListIsSynaWithUid:(NSInteger)uid BookId:(NSInteger)bookId;
//服务器是否含有该书录音
-(void)isRecordExistOnNetWithUid:(NSInteger)uid BookId:(NSInteger)bookId CheckComplete:(void (^)(BOOL isExist))checkComplete ;
//同步正本书录音(根据服务器的List 自动筛选服务器较新的录音)
-(void)downloadRecordsWithWithUid:(NSInteger)uid BookId:(NSInteger)bookId oneCompletionHandler:(DownloadComplete_One)completionHandler allComplete:(DownloadComplete_All)allComplete;
//根据页码同步书本
-(void)downloadRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId PageId:(NSInteger)pageId completionHandler:(void (^)(NSURLResponse *response, NSURL *filePath, NSError *error))completionHandler;
//取消所有下载任务
-(void)cancelAllDownloadTask;
//按照书本某页取消下载任务
-(void)cancelDownloadTaskUid:(NSInteger)uid BookId:(NSInteger)bookId CurrentPage:(NSInteger)currentPage;

//删除
//该书是否有本地录音
-(BOOL)isBookRecordExistWithUid:(NSInteger)uid BookId:(NSInteger)bookId;
//是否包含该页录音(本地)
-(BOOL)isExistRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId CurrentPage:(NSInteger)currentPage;
//删除整本书的录音
-(void)deleteBookRecordsWithUid:(NSInteger)uid BookId:(NSInteger)bookId;
//删除某一页的录音
-(void)deletePageRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId PageId:(NSInteger)pageId;
//删除本地录音
-(void)deleteLoaclRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId PageId:(NSInteger)pageId;
//删除废弃录音
-(void)deleteRubbishRecordWithKeyPath:(NSString*)keyPath;
//
//是否有需要同步的离线数据
-(BOOL)isNeedSyanRecordWithUid:(NSInteger)uid BookId:(NSInteger)bookId;
//同步离线数据
-(void)synaOffLineDataWithUid:(NSInteger)uid AllComplete:(void(^)())allComplete Failure:(void(^)(NSError* error))failure;

//网络重新连接,将上传失败的录音重新上传
-(void)reUploadFailedRecordsWithUid:(NSInteger)uid AllUpload:(void(^)())allUpload Failure:(void(^)(NSError* error))failure;
//网络连接,同步删除同步失败数据
-(void)reDeleteRecordsWithUid:(NSInteger)uid AllReDelete:(void(^)())allReDelete Failure:(void(^)(NSError* error))failure;

//初始化(打开)
-(void)bookOpenInitUid:(NSInteger)uid BookId:(NSInteger)bookId;
//关闭书本
-(void)closeBook;
@end
